import request from "@/utils/request";

export default {
  getUserList(searchModel) {
    return request({
      url: "/user/list",
      method: "get",
      params: {
        pageNo: searchModel.pageNo,
        pageSize: searchModel.pageSize,
        username: searchModel.username,
        phone: searchModel.phone,
      },
    });
  },

  addUser(user) {
    return request({
      url: "/user",
      method: "post",
      data: user,
    });
  },

  getUserById(id) {
    return request({
      url: `/user/${id}`,
      method: "get",
    });
  },

  saveUser(user) {
    if (user.id == null && user.id == undefined) {
      return this.addUser(user);
    }
    return this.updateUser(user);
  },

  updateUser(user) {
    return request({
      url: `/user`,
      method: "put",
      data: user,
    });
  },

  deleteUserById(id) {
    return request({
      url: `/user/${id}`,
      method: "delete",
    });
  },

  getInfo(token) {
    return request({
      url: `/user/info`,
      method: "get",
      params: { token },
    });
  },

  updatePassword(data) {
    return request({
      url: `/user/updatePassword/${data.id}`,
      method: "put",
      data: {
        rePassword: data.rePassword,
        upPassword: data.upPassword,
        model: data.model,
      },
    });
  },
  updateUserInfo(user) {
    return request({
      url: `/user/updateUserInfo`,
      method: "put",
      data: user,
    });
  },

  getUserByName(username) {
    return request({
      url: `/user/getByName`,
      method: "get",
      params: { username: username },
    });
  },
};
